package com.jbob.collection;

import java.util.ArrayList;

/**
 * Classe de collection de balise
 * @author lucas.bouabdelli jean-baptiste.guy
 */
public class Balise implements Comparable<Balise>
{
	private String name;
	private String path;
	private double pertinence;
	private String doc;
	private ArrayList<Terme> termes;
	
	public Balise() 
	{
		termes = new ArrayList<>();
	}
	
	public String getPath() 
	{
		return path;
	}
	public void setPath(String path) 
	{
		this.path = path;
	}
	public ArrayList<Terme> getTermes() 
	{
		return termes;
	}
	public void setTermes(ArrayList<Terme> termes) 
	{
		this.termes = termes;
	}
	public String getName() 
	{
		return name;
	}
	public void setName(String name) 
	{
		this.name = name;
	}
	public void addTerm(String name, int position)
	{
		position++;
		Terme t = new Terme();
		t.setNom(name);
		t.addOccurenceAt(position);
		
		if(termes.contains(t))
		{
			int pos = termes.indexOf(t);
			termes.get(pos).addOccurenceAt(position);
		}
		else
		{
			termes.add(t);
		}
	}
	
	public void addTerms(String name, String positions, double poids)
	{
		Terme t = new Terme();
		t.setNom(name);
		t.addOccurencesAt(positions);
		t.setPoids(poids);
		
		termes.add(t);
	}
	
	@Override
	public String toString() 
	{
		StringBuilder builder = new StringBuilder();
		builder.append(name);
		builder.append(System.lineSeparator());
		builder.append(path);
		builder.append(System.lineSeparator());
		for(Terme terme : termes)
		{
			builder.append(terme.toString());
			builder.append(System.lineSeparator());
		}
		return builder.toString();
	}

	public double getPertinence() {
		return pertinence;
	}

	public void setPertinence(double pertinence) {
		this.pertinence = pertinence;
	}

	@Override
	public int compareTo(Balise o) 
	{
		return (int) ((this.getPertinence() - o.getPertinence()) * 1000000);
	}

	public String getDoc() {
		return doc;
	}

	public void setDoc(String doc) {
		this.doc = doc;
	}


}
